//
//  M1PersonalViewController.m
//  NewMarryU
//
//  Created by apple on 2018/7/11.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1PersonalViewController.h"
#import "M1PersonalListCell.h"
#import "M1_PersonalHeaderView.h"
#import "M1PersonalDataVC.h"
#import "M1PhotoGalleryVC.h"
#import "M1CertificationVC.h"
#import "M1RecentFriendsVC.h"
#import "M1SettingUpVC.h"
#import "M1LikeListVC.h"

@interface M1PersonalViewController ()<M1_HeaderViewPushDelegate>

@property (nonatomic, strong) M1_PersonalHeaderView *m1_headerView;

@end

@implementation M1PersonalViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    WEAKSELF
    [M1User m1_uploadInfo:^(M1User *user) {
        [weakSelf.m1_headerView m1_setData];
        [weakSelf.m1_tableView reloadData];
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.m1_hiddenNav = YES;
    
    self.m1_tableView.backgroundColor = m1_color(0xF6F8FB);
    
    [self.m1_tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    
    self.m1_headerView = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([M1_PersonalHeaderView class]) owner:nil options:nil] firstObject];
    
    self.m1_headerView.frame = CGRectMake(0, 0, SCREENWIDTH, 260 + STATUS_HEIGHT);
    
    self.m1_headerView.delegate = self;
    
    self.m1_tableView.tableHeaderView = self.m1_headerView;
    
    [self.m1_tableView registerNib:[UINib nibWithNibName:@"M1PersonalListCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:m1_tableViewCellIdentifier];
    
}

#pragma mark - headerViewDelegate
- (void)m1_certificationPushVC:(NSInteger)type{
    NSLog(@"%ld", type);
    if (type == 0 && [M1User user].basic.identity_info.identity_auth.auth_status != 1) {
        return;
    }
    M1CertificationVC *cerVC = [[M1CertificationVC alloc] init];
    cerVC.m1_title = @[@"身份信息勋章", @"学历信息勋章", @"房产信息勋章", @"汽车信息勋章"][type - 1];
    cerVC.m1_type = type - 1;
    cerVC.m1_changeNavTitleColor = YES;
    cerVC.m1_changeBackImage = YES;
    cerVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:cerVC animated:YES];
}

- (void)m1_pushToLikeVC{
    NSLog(@"喜欢");
    M1LikeListVC *likeVC = [[M1LikeListVC alloc] init];
    likeVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:likeVC animated:YES];
}

- (void)m1_pushToDetailsVC{
    NSLog(@"详情");
    M1PersonalDataVC *editVC = [[M1PersonalDataVC alloc] init];
    editVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:editVC animated:YES];
}

- (void)m1_pushToPhotoAlbumVC{
    NSLog(@"相册");
    M1PhotoGalleryVC *photoVC = [[M1PhotoGalleryVC alloc] init];
    photoVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:photoVC animated:YES];
}

#pragma mark - tableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        M1VIPCenterVC *m1_vipVC = [[M1VIPCenterVC alloc]init];
        m1_vipVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:m1_vipVC animated:YES];
    }
    else if (indexPath.row == 1){
        M1RecentFriendsVC *recentVC = [[M1RecentFriendsVC alloc] init];
        recentVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:recentVC animated:YES];
    }else{
        M1SettingUpVC *setVC = [[M1SettingUpVC alloc] init];
        setVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:setVC animated:YES];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 54;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    M1PersonalListCell *cell = [tableView dequeueReusableCellWithIdentifier:m1_tableViewCellIdentifier];
    
    NSArray *iconArr = @[@"personal_icon_vip",@"personal_icon_call", @"personal_icon_set"];
    
    NSArray *titleArr = @[@"会员中心",@"访问我的", @"设置"];
    
    cell.m1_icon.image = LOAD_LOCAL_IMG(iconArr[indexPath.row]);
    
    cell.m1_title.text = titleArr[indexPath.row];
    
    if (indexPath.row == 0) {
        if ([M1User user].status.member_fees_status == 1) {
            if ([M1User user].status.is_lifelong == 1) {
                cell.m1_date.text = @"终身会员";

            }else{
                cell.m1_date.text = [NSString stringWithFormat:@"剩余%ld天", [M1User user].status.member_day];
            }
            cell.m1_date.hidden = NO;
        }else{
            cell.m1_date.hidden = YES;
        }
    }else{
        cell.m1_date.hidden = YES;
    }
    
    if (indexPath.row == 3) {
        cell.m1_line.hidden = YES;
    }else{
        cell.m1_line.hidden = NO;
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
